package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;

import com.ruoyi.system.api.domain.SysRole;
import com.ruoyi.system.service.ISysRoleService;

/**
 * 角色信息内部Controller，实现远程feign接口com.ruoyi.system.api.RemoteSysRoleService。
 * 
 * @author ruoyi
 * @date 2023-04-27
 */
@RestController
@RequestMapping("/inner/role")
public class SysRoleInnerController
{
    @Autowired
    private ISysRoleService sysRoleService;

    /**
     * 查询角色信息列表
     */
    @InnerAuth
    @PostMapping("/list")
    public R<List<SysRole>> selectSysRoleList(SysRole sysRole)
    {
        List<SysRole> list = sysRoleService.selectRoleList(sysRole);
        return R.ok(list);
    }

    /**
     * 获取角色信息详细信息
     */
    @InnerAuth
    @GetMapping(value = "/{roleId}")
    public R<SysRole> selectSysRoleByRoleId(@PathVariable("roleId") Long roleId)
    {
        SysRole sysRole = sysRoleService.selectRoleById(roleId);
        return R.ok(sysRole);
    }

    /**
     * 新增角色信息
     */
    @InnerAuth
    @PostMapping
    public R<Integer> insertSysRole(@RequestBody SysRole sysRole)
    {
        Integer result = sysRoleService.insertRole(sysRole);
        return R.ok(result);
    }

    /**
     * 修改角色信息
     */
    @InnerAuth
    @PutMapping
    public R<Integer> updateSysRole(@RequestBody SysRole sysRole)
    {
        Integer result = sysRoleService.updateRole(sysRole);
        return R.ok(result);
    }

    /**
     * 批量删除角色信息
     */
	@InnerAuth
	@DeleteMapping("/{roleIds}")
    public R<Integer> deleteSysRoleByRoleIds(@PathVariable Long[] roleIds)
    {
        Integer result = sysRoleService.deleteRoleByIds(roleIds);
        return R.ok(result);
    }

}
